package com.forehope.portal.aslpUtil;

import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.database.RowMapper;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.bpms.util.UtilDate;
import com.actionsoft.bpms.util.UtilString;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.AppAPI;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;

public class MeetingUtil {
    public List<String> searchMeetingDate(String uid) {
        List<String> result = new ArrayList<>();
        String userAlias = uid;
        if (!UtilString.isEmpty(uid)) {
            userAlias = SDK.getORGAPI().getUserAliasNames(uid);
        }
        String sql = "SELECT DISTINCT(a.BOOKDATE) FROM APP_ACT_MEETINGMANAGER_BOOK a LEFT JOIN BO_ACT_MM_REQUEST_CONFIRM b ON a.BINDID=b.BINDID AND b.USERID='"+uid+"' WHERE (a.USERID='"+uid+"' OR a.ATTENDANCE LIKE '%"+userAlias+"%') ORDER BY a.BOOKDATE";
        List<RowMap> list = DBSql.getMaps(sql);
        for (RowMap rowMap:list){
            result.add(rowMap.getString("BOOKDATE"));
        }
        return result;
    }

    /**
     * 查询会议列表
     *
     * @return
     */
    public List<RowMap> getDateMeetingList(String searchDate, String userId) {
        String userAlias = userId;
        if (!UtilString.isEmpty(userId)) {
            userAlias = SDK.getORGAPI().getUserAliasNames(userId);
        }
        String sql  = "SELECT a.*,b.ACTIONTYPE FROM APP_ACT_MEETINGMANAGER_BOOK a LEFT JOIN BO_ACT_MM_REQUEST_CONFIRM b ON a.BINDID = b.BINDID AND b.USERID ='"+userId+"' LEFT JOIN BO_ACT_MM_ROOM c ON a.ROOMID = c.ROOMID WHERE( a.USERID = '"+userId+"' OR a.ATTENDANCE LIKE '%"+userAlias+"%' ) AND  (a.BOOKTIMEBEGIN BETWEEN TO_DATE('"+searchDate+" 00:00:00','YYYY-MM-DD HH24:MI:SS') AND TO_DATE('"+searchDate+" 23:59:59','YYYY-MM-DD HH24:MI:SS'))";
        List<RowMap> list = DBSql.getMaps(sql);
        return list;
    }
}
